package com.hhly.rabbitmq.header;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.hhly.rabbitmq.RabbitMQUtil;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Consumer;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

public class Receive {
    public static void main(String[] args) throws Exception {
    	Channel channel = RabbitMQUtil.getChannel();
    	  channel.exchangeDeclare(Send.EXCHANGE_NAME, "headers");
    	  String queueName = channel.queueDeclare().getQueue();
          Map<String, Object> headers = new HashMap<>();  
          headers.put("x-match", "any");//all any  
          headers.put("aaa", "01234");  
          
          channel.queueBind(queueName, Send.EXCHANGE_NAME,"", headers); 
          Consumer consumer = new DefaultConsumer(channel) {
  			@Override
  			public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
  					byte[] body) throws IOException {
  				String message = new String(body, "UTF-8");
  				System.out.println(" [x] Received '" + message + "'");
  			}
  		};
  		channel.basicConsume(queueName, true, consumer);
	}
}
